package com.shine.app.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.shine.app.AppManager;
import com.shine.app.BaseActivity;
import com.shine.app.R;
import com.shine.app.commons.StringUtils;
import com.shine.app.commons.UIHelper;
import com.shine.app.inject.InjectView;
import com.shine.app.inject.Injector;
import com.shine.app.widget.ProgressWebView;

@SuppressLint("SetJavaScriptEnabled")
public class SlideFeedbackActivity extends BaseActivity implements
		OnClickListener {
	@InjectView(R.id.head_back)
	private ImageView head_backImageView;
	@InjectView(R.id.head_seacher)
	private ImageView head_searchImageView;
	@InjectView(R.id.head_name)
	private TextView head_nameTextView;
	@InjectView(R.id.webview)
	private ProgressWebView webView;
	private String url = "http://info.opentee.com/contact-us-b2c/";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.slide_feedback_webview);
		Injector.get(this).inject();

		head_nameTextView.setText(R.string.set_contact);
		head_backImageView.setOnClickListener(this);
		head_searchImageView.setOnClickListener(this);
		WebSettings webSettings = webView.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webView.setDownloadListener(new DownloadListener() {
			@Override
			public void onDownloadStart(String url, String userAgent,
					String contentDisposition, String mimetype,
					long contentLength) {
				if (!StringUtils.isEmpty(url) && url.startsWith("http://")) {
					startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
				}
			}
		});
		webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		webView.loadUrl(url);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.head_back:
			AppManager.getAppManager().finishActivity();
			overridePendingTransition(R.anim.anim, R.anim.slide_out_down);
			break;

		case R.id.head_seacher:
			UIHelper.showHome(this);
			overridePendingTransition(R.anim.anim, R.anim.slide_out_down);
			break;

		default:
			break;
		}
	}

}
